// ValidationAspects
// Written by Mike Saunders
// Released under Microsoft Public License (Ms-PL)
using NUnit.Framework;
using ValidationAspects.Exceptions;
using ValidationAspects.Factories;

namespace TestValidationAspects.Factories
{
	[TestFixture]
	public class TestMaximumLength
	{
		private static void Fail(int length, string actual)
		{
			Test.Throws<ValidateMaximumLengthException>(() => new MaximumLength {Length = length}.Create<string>().Invoke(actual, new MockValidationContext()),
			                                            new ValidateMaximumLengthException(length, actual.Length).Message);
		}

		private static void Pass(int length, string actual)
		{
			new MaximumLength {Length = length}.Create<string>().Invoke(actual, new MockValidationContext());
		}

		[Test]
		public void Test_MaximumLength()
		{
			Pass(0, string.Empty);
			Fail(3, "test");
			Pass(4, "test");
			Pass(5, "test");
		}

		[Test]
		public void Test_validation_skips_null_value()
		{
			Pass(0, null);
		}
	}
}